package com.aos.dao;

import com.aos.entity.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by quxiaoyan
 */
public interface RoleDao extends JpaRepository<Role, Long> {

    /**
     *
     * @Description:查询角色信息
     *
     */
    Role findByRid(long rid);

    /**
     *
     * @Description:新增角色信息
     *
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "insert into role (rid, rname) values (?1,?2)",nativeQuery = true)
    int insertRoleByRid(long rid,String rname);

    /**
     *
     * @Description:更新角色信息
     *
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update role set rname =?2 where rid = ?1",nativeQuery = true)
    int updateRoleByRid(long rid,String rname);

    /**
     *
     * @Description:删除角色信息
     *
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "delete from role where rid = ?1",nativeQuery = true)
    int deleteRoleByRid(long rid);
}
